package view.panel.feed
{
	import control.panel.FeedPanelControl;
	import control.panel.IPanelControl;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import global.GameState;
	
	import utils.TextTool;
	
	import view.components.CheckButton;
	import view.components.ImgButton;
	import view.components.Radio;
	import view.components.RadioGroup;
	import view.panel.AbsPanel;
	
	public class FeedPanel extends AbsPanel
	{
		
		private var canvas:Bitmap;
		private var text:TextField;
		public var feedText:*;
		
		private var uploadPicCBut:CheckButton;
		private var wrongRadio:Radio;
		private var adviseRadio:Radio;
		private var shareRadio:Radio;
		private var selfRadio:Radio;
		
		private var radioGroup:RadioGroup;
		
		private var feedBut:ImgButton;
		private var hintText:TextField;
		
		public function FeedPanel(panelControl:IPanelControl)
		{
			super(panelControl);
			defaultX = 150;
			defaultY = 86;
			resetBg(480,300);
			initCloseBut();
			resetCloseBut();
			dropShadow();
			initTweenPanelOpen();
			initTitle("text_title_feed");
			initText();
			initBut();
			
			
			initSelectButs();
		}
		
		private function initBut():void
		{
			feedBut = new ImgButton(300,256,0,onBut,57,27,"butBg",null,"提交");
			addChild(feedBut);
			addChild(new ImgButton(388,256,1,onBut,57,27,"butBg",null,"取消"));
		}
		
		private function onBut(event:MouseEvent):void
		{
			switch (event.target.id)
			{
				case 0:
					(panelControl as FeedPanelControl).upload();
					
					break;
				case 1:
					close();
					break;
			}
		}
		
		private function initSelectButs():void
		{
			wrongRadio = new Radio(34,216,0,onRadio);
			wrongRadio.setTitle("游戏错误");
			wrongRadio.selected = true;
			addChild(wrongRadio);
			
			uploadPicCBut = new CheckButton(309,216,0);
			uploadPicCBut.setTitle("上传屏幕截图");
			addChild(uploadPicCBut);
			uploadPicCBut.selected = true;
			
			adviseRadio = new Radio(143,216,1,onRadio);
			adviseRadio.setTitle("意见与建议");
			addChild(adviseRadio);
			
			shareRadio = new Radio(34,243,2,onRadio);
			shareRadio.setTitle("分享牌局");
			addChild(shareRadio);
			
			selfRadio = new Radio(143,243,3,onRadio);
			selfRadio.setTitle("非公开意见");
			addChild(selfRadio);
			
			canvas = new Bitmap();
			canvas.x = 259;
			canvas.y = 57;
		
			addChild(canvas);
			
			radioGroup = new RadioGroup();
			radioGroup.addRadio(wrongRadio);
			radioGroup.addRadio(adviseRadio);
			radioGroup.addRadio(shareRadio);
			radioGroup.addRadio(selfRadio);
		}
		
		private function onRadio(event:MouseEvent):void
		{
			
		}
		
		private function initText():void
		{
			text = TextTool.getTextField(350,20,12,0xFFFFFF);
			text.x = 65;
			text.y = 30;
			addChild(text);
			text.text = "欢迎您向我们反馈错误，如果错误确实存在，将会给你奖励的哦！";
			
			
			feedText = TextTool.getTextArea(238,147,true);
			feedText.textField.maxChars = 255;
			feedText.x = 11;
			feedText.y = 57;
			addChild(feedText);
			
			hintText = TextTool.getTextField(200,20,12,0xFF6600,false,false,"center");
			hintText.x = 260;
			hintText.y = 234;
			addChild(hintText);
		}
		
		public function hint(text:String):void
		{
			hintText.text = text;
		}
		
		public function enableFeedBut(v:Boolean):void
		{
			feedBut.mouseEnabled = v;
		}
		
		public function get type():int
		{
			return radioGroup.selectedIndex;
		}
		
		public function get content():String
		{
			return feedText.text;
		}
		
		public function showCanvas(bitmapData:BitmapData):void
		{
			canvas.bitmapData = bitmapData;
			canvas.scaleX = canvas.scaleY =  208 / GameState.GAME_WIDTH / .8;
		}
		
		public function set enableFeedText(v:Boolean):void
		{
			feedText.textField.selectable = v;
		}
		
		override public function close() : void
		{
			super.close();
			(panelControl as FeedPanelControl).close();
		}
		
	}
}